<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/admin.css" />
	<script type='text/javascript' src='__PUBLIC__/js/jquery.min.js'></script>
	<script type='text/javascript' src='__PUBLIC__/layer/layer.js'></script>
	<script type='text/javascript' src='__PUBLIC__/admin/js/common.js'></script>
    <title>后台管理</title>
</head>
<body>
<div class="main-container clearfix"><div class="main-content"><div class="inner"><div class="mall-manage">
    <div class="comm-list" style="min-height:600px">
        <div class="comm-top">
            <h4 style="margin-bottom:0"><{:$vo['id'] ? '修改' : '添加'}><{:I('get.type')==1?'医生':'营养师'}></h4>
            <div class="add_page_top"></div>
        </div>
        <form id="memberform" onsubmit="return false;">
            <input type="hidden" name="info[id]" value="<{$vo.id}>" />
            <input type="hidden" name="info[type]" value="<{$Think.get.type}>" />
            <input type="hidden" id="info_pic" name="info[pic]" value="<{$vo.pic}>" />
            <div class="shop_sort_box">
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>头像：</h4></div>
                    <div class="shop_sort_set" style="position:relative;">
                        <input class="shop_sort_text" type="text" onclick="up_img_fun()" />
                        <a href="javascript:void(0);" class="btn-upload" onclick="up_img_fun()">
                            <i class="icons icons-upload"></i>上传
                        </a>
                        <span class="input_span_extra">&nbsp;&nbsp;&nbsp;建议图片尺寸300px*300px</span>
                    </div>
                </div>
                <div class="shop_sort" <if condition="$vo['pic'] eq ''">style="display:none;"</if> >
                    <div class="shop_sort_title"><h4>&nbsp;</h4></div>
                    <div class="shop_sort_set" id="pic_wrapper">
                        <img src="<{$vo.pic}>" />
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>姓名：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[name]" value="<{$vo.name}>" type="text" />
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>手机号：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[phone]" value="<{$vo.phone}>" type="text" />
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>年龄：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[age]" value="<{$vo.age}>" type="text" />
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>性别：</h4></div>
                    <div class="shop_sort_set">
                        <label class="lbl">
                            <span><input name="info[sex]" type="radio" value="1" <{:$vo['sex']!='2'?'checked': ''}> /></span>
                            <span>男</span>
                        </label>
                        <label class="lbl">
                            <span><input name="info[sex]" type="radio" value="2" <{:$vo['sex']=='2'?'checked': ''}> /></span>
                            <span>女</span>
                        </label>
                    </div>
                </div>
                <if condition="$_GET['type'] eq '1'">
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>所在市：</h4></div>
                    <div class="shop_sort_set">
                        <select class="shop_sort_text" name="info[city_id]" onchange="getHpt(this)">
                            <option value="">请选择所在市</option>
                            <foreach name="cityRow" key="k" item="v">
                                <option value="<{$k}>" <{:$k==$vo['city_id']?'selected': ''}> ><{$v}></option>
                            </foreach>
                        </select>
                        <a class="input_span_extra_a" href="<{:U('HptCity/edit')}>">+添加市</a>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>所在医院：</h4></div>
                    <div class="shop_sort_set">
                        <select class="shop_sort_text" name="info[hpt_id]">
                        </select>
                        <a class="input_span_extra_a" href="<{:U('Hospital/edit')}>">+添加医院</a>
                    </div>
                </div>
                </if>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>简介：</h4></div>
                    <div class="shop_sort_set">
                        <textarea class="shop_sort_text" style="height:150px;" name="info[des]" maxlength="200" placeholder="200字以内"><{$vo.des}></textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>发表论文：</h4></div>
                    <div class="shop_sort_set">
                        <textarea class="shop_sort_text" style="height:150px;" name="info[paper]"><{$vo.paper}></textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title">
                        <h4>&nbsp;</h4>
                    </div>
                    <div class="shop_sort_set">
                        <span onclick="save(this);return false" id="saveBtn" class="btngreen30">完成</span>
                        &nbsp;&nbsp;&nbsp;
                        <span onclick="history.go(-1);" class="btngray30">返回</span>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div></div></div></div>
<!-- 上传图片开始 -->	
<link rel="stylesheet" type="text/css" href="__PUBLIC__/upimg/css/upimg.css" />
<script type="text/javascript" src="__PUBLIC__/upimg/upimg.js"></script>
<script type="text/javascript">
/**
 * up_img_fun(up_img_php) 执行上传的函数，微沟通图片上传的改版
 * @param string up_img_php 后台处理图片上传的文件
 * 
 * up_img_notify(img_path) 上传回调函数
 * @param string img_path 返回的图片地址，图片仍放在/data/image_c/下
 */
function up_img_notify(img_path){
    $('#info_pic').val(img_path);
    $('#pic_wrapper').parent().show();
    $('#pic_wrapper img').attr('src',img_path);
}
</script>
<!-- 上传图片结束 -->
<script>
function save(obj){
    if($("input[name='info[pic]']").val()==''){
        note_info('请上传头像',obj,'warn');return;
    }
    if($("input[name='info[name]']").val()==''){
        note_info('姓名不能为空',obj,'warn');return;
    }
    if(!isMobil($("input[name='info[phone]']").val())){
        note_info('请填写正确的手机号',obj,'warn');return;
    }
    if($("input[name='info[age]']").val()==''){
        note_info('年龄不能为空',obj,'warn');return;
    }
    if('<{$Think.get.type}>' == '1' && !$("select[name='info[hpt_id]']").val()){
        note_info('请选择所在医院',obj,'warn');return;
    }
    
    $.post('<{:U("edit")}>',$('#memberform').serialize(),function(res){
        res=$.trim(res);
        if(res=='suc'){
            note_info('保存成功！',obj);
            setTimeout('window.location.href="<{$upPageUrl}>"',1200);
        }else if(res=='cf'){
            note_info('该手机号已被注册',obj,'warn');
        }else{
            note_info('保存失败或未改动',obj,'warn');
        }
    })
}
//获取医院
function getHpt(obj){
    $.post("<{:U('Hospital/getHptByCid')}>",{cid:$(obj).val()},function(res){
        var htmlStr = '';
        if(res.length > 0){
            $.each(res,function(i,item){
                htmlStr += '<option value="'+item.id+'">'+item.name+'</option>';
            });
        }
        $("select[name='info[hpt_id]']").html(htmlStr);
    },'json');
}
//修改页面时
$(function(){
    if('<{$vo.id}>'){
        $.post("<{:U('Hospital/getHptByCid')}>",{cid:'<{$vo.city_id}>'},function(res){
            if(res.length > 0){
                var htmlStr = '';
                $.each(res,function(i,item){
                    if(item.id == '<{$vo.hpt_id}>'){
                        htmlStr += '<option selected value="'+item.id+'">'+item.name+'</option>';
                    }else{
                        htmlStr += '<option value="'+item.id+'">'+item.name+'</option>';
                    }
                });
                $("select[name='info[hpt_id]']").html(htmlStr);
            }
        },'json');
    }
});
//验证手机号
function isMobil(s){
    var patrn=/^1[0-9]{10}$/;  
	if (!patrn.exec(s)) return false
	return true
}
</script>